﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services.Protocols;
using System.Data;

/// <summary>
/// Summary description for SelectMail
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
public class SelectMail : System.Web.Services.WebService {


    public SelectMail()
    {

    }
    [WebMethod]
    public string[] GetSEAList(string prefixText)
    {
        string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

        string selectString = "select p.product from products p  INNER JOIN company_product tt ON (tt.product_id = p.id)where tt.company_id=" + Session["company_id"].ToString();//WHERE email1 LIKE '" + prefixText + "%'";

        List<String> SEAList = new List<string>(10);
        using (SqlConnection sqlConn = new SqlConnection(connString))
        {
            sqlConn.Open();

            using (SqlCommand sqlCmd = new SqlCommand(selectString, sqlConn))
            {
                SqlDataReader reader = sqlCmd.ExecuteReader();
                while (reader.Read())
                    SEAList.Add(reader[0].ToString());
            }
            sqlConn.Close();
        }

        return (SEAList.ToArray());
    }   
    
    [WebMethod]
    public string[] GetCustList(string prefixText,int count)
    {
        string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

        string selectString = "SELECT email1   from companies  union SELECT email1   from publishers union SELECT email1   from distributers";//WHERE email1 LIKE '" + prefixText + "%'";

        List<String> CustList = new List<string>(10);
        using (SqlConnection sqlConn = new SqlConnection(connString))
        {
            sqlConn.Open();

            using (SqlCommand sqlCmd = new SqlCommand(selectString, sqlConn))
            {
                SqlDataReader reader = sqlCmd.ExecuteReader();
                while (reader.Read())
                    CustList.Add(reader[0].ToString());
            }
            sqlConn.Close();
        }
       
        return (CustList.ToArray());
    }
    [WebMethod]
    public List<String> GetACTList(string prefixText)
    {
        string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

        string selectString ="SELECT product from products WHERE product LIKE N'%" + prefixText + "%'";

       //////////////////////////////
        List<String> ds = new List<String>();
     DataTable dt = (DB.getdata(selectString)).Tables[0];//
     foreach (DataRow dr in dt.Rows)
     {
         ds.Add(dr[0].ToString());
      
     }
        return ds;
        
    }

    private object DataTable(System.Data.DataSet dataSet)
    {
        throw new NotImplementedException();
    }
  
}

